import io from 'socket.io-client'
import store from '../store'

const socket = io()
// 进行连接建立的监听
socket.on('connect', () => {
    console.log('和服务器已建立连接...')
})
  // 监听服务器获取uid, 二维码
socket.on('sendQRcode', ({ uuid, QRcode }) => {
     store.commit('getUuid', uuid)
     store.commit('getGrcode', QRcode)
})
// 未扫码 等待扫码
socket.on('waitScanCode', () => {
  store.commit('waitScanCode')
})
// 用户扫码 并且确认过
socket.on('SuccessScanCode', (userInfo) => {
  store.commit('scanSuccess', userInfo)
})
// 已扫码  好久不确认
socket.on('ScanCodeOvertime', () => {
  store.commit('modeifyScanTip', '二维码失效')
})
// 已扫码 未确认
socket.on('ScanCodeing', (event) => {
  store.commit('ScanCodeing')
})
// // 移动端扫码成功
socket.on('AuthorizedWebSuccess', res => {
  store.commit('AuthorizedWebSuccess', res)
});
// 监听socket的断开，为了控制按钮
socket.on('disconnect', () => {
  console.log('和服务端断开连接...')
})
export default socket